﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using KaoWuYouLibs.Common;
using KaoWuYouLibs.Model;

namespace KaoWuYouLibs.Dal
{
    public class SubjectAccess
    {
        public List<SubjectModel> FindAllSubjects()
        {

            SqlConnection conn = new SqlConnection(Tools.ConnString);
            try
            {
                conn.Open();
                List<SubjectModel> re = new List<SubjectModel>();
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = "SELECT * FROM Subject";
                SqlDataReader sdr = cmd.ExecuteReader();
                while (sdr.Read())
                {
                    SubjectModel tmp = new SubjectModel()
                    {
                        SubjectID = (int)sdr["SubjectID"],
                        SubjectName = sdr["SubjectName"] as string
                    };
                    re.Add(tmp);
                }
                sdr.Close();
                return re;
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                conn.Close();
            }
        }
    }
}
